package coml.jiyun.hp.gjtk_b;

import android.os.Bundle;
import android.widget.TextView;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import coml.jiyun.hp.gjtk_b.adapter.MainAdapter;
import coml.jiyun.hp.gjtk_b.fragment.HomeFragment;
import coml.jiyun.hp.gjtk_b.fragment.WebFragment;

public class MainActivity extends AppCompatActivity {

    /**
     * 首页
     */
    private TextView mMainTv;
    private Toolbar mMainTool;
    private ViewPager mMainVp;
    private TabLayout mMainTab;
    private ArrayList<Fragment> fragments;
    private ArrayList<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mMainTv = (TextView) findViewById(R.id.main_tv);
        mMainTool = (Toolbar) findViewById(R.id.main_tool);
        mMainVp = (ViewPager) findViewById(R.id.main_vp);
        mMainTab = (TabLayout) findViewById(R.id.main_tab);

        fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new WebFragment());

        list = new ArrayList<>();
        list.add("首页");
        list.add("网页");

        MainAdapter mainAdapter = new MainAdapter(getSupportFragmentManager(), fragments, list);
        mMainVp.setAdapter(mainAdapter);
        mMainTab.setupWithViewPager(mMainVp);
    }
}
